package com.panopset.flywheel;

/**
 * A template command is specified in a script, and has a source.
 *
 * @author Karl Dinwiddie
 */
public abstract class TemplateCommand extends Command {
    public final String  source;
    public final String  innerPiece;
    private final String params;

    @Override
    public String getDescription() {
        return params;
    }

    public TemplateCommand(String source, String innerPiece, String params,
            Template template) {
        super(template);
        this.source = source;
        this.innerPiece = innerPiece;
        this.params = params;

    }

    /**
     * @return the exact directive as it appears in the template file.
     */
    public String getFullSource() {
        return template.flywheel.openDirective + source + template.flywheel.closeDirective;
    }

    public String getParams() {
        if (params == null) {
            return "";
        } else {
            if (params.length() > template.flywheel.directive.length()
                    && params.indexOf(template.flywheel.directive) == 0) {
                return template.flywheel.get(
                        params.substring(template.flywheel.directive.length()));
            } else {
                return params;
            }
        }
    }
}
